//
//  StatusTopCell.swift
//  weibo 666
//
//  Created by mac on 15/11/10.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

class StatusTopCell: UIView {
    var viewModel: StatusViewModel? {
        didSet{
            ///姓名
            nameLabel.text = viewModel?.status.user?.screen_name
            ///头像
            iconView.sd_setImageWithURL(viewModel?.userProfileUrl,placeholderImage: viewModel?.defaultImage)
            ///会员图标
            vipIconView.image = viewModel?.userVipImage
            ///认证图标
            memberIconView.image = viewModel?.userMenberImage
            // TODO: - 后续会讲
            timeLabel.text = "刚刚"
            sourceLabel.text = "承义微博"
            
        }
    }
    
    //MARK: - 构造函数
    override init(frame: CGRect) {
        super.init(frame: frame)
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //MARK: - 懒加载控件
    ///用户头像
    private lazy var iconView: UIImageView = UIImageView(imageName: "avatar_default_big")
    ///姓名标签
    private lazy var nameLabel: UILabel = UILabel(title: "我就是你爹")
    ///会员图标
    private lazy var memberIconView: UIImageView = UIImageView(imageName: "common_icon_membership_level1")
    ///认证标签
    private lazy var vipIconView: UIImageView = UIImageView(imageName: "avatar_grassroot")
    ///时间标签
    private lazy var timeLabel: UILabel = UILabel(title: "刚刚", fontSize: 11, color: UIColor.orangeColor())
    ///来源标签
    private lazy var sourceLabel: UILabel = UILabel(title: "承义微博", fontSize: 14, color: UIColor.redColor())
    
}
//MARK: - 布局界面
extension StatusTopCell{
    private func setupUI(){
        //背景颜色
        backgroundColor = UIColor.whiteColor()
        //添加控件
        let sepView = UIView()
        sepView.backgroundColor = UIColor.blackColor()
        addSubview(sepView)
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(memberIconView)
        addSubview(vipIconView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        
        // 2. 自动布局
        sepView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self.snp_left)
            make.right.equalTo(self.snp_right)
            make.height.equalTo(StatusCellMagrin)
        }
        iconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(sepView.snp_bottom).offset(StatusCellMagrin)
            make.left.equalTo(self.snp_left).offset(StatusCellMagrin)
            make.width.equalTo(StatusIconWidth)
            make.height.equalTo(StatusIconWidth)
        }
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView.snp_top)
            make.left.equalTo(iconView.snp_right).offset(StatusCellMagrin)
        }
        memberIconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(nameLabel.snp_top)
            make.left.equalTo(nameLabel.snp_right).offset(StatusCellMagrin)
        }
        vipIconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView.snp_right)
            make.centerY.equalTo(iconView.snp_bottom)
        }
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(iconView.snp_bottom)
            make.left.equalTo(iconView.snp_right).offset(StatusCellMagrin)
        }
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(timeLabel.snp_bottom)
            make.left.equalTo(timeLabel.snp_right).offset(StatusCellMagrin)
        }
    }
    
}
